//
//  HWOnlinegameTableCell.m
//  94hwanGame
//
//  Created by Chendaobin on 2019/8/22.
//  Copyright © 2019年 王治庭. All rights reserved.
//

#import "HWOnlinegameTableCell.h"

@interface HWOnlinegameTableCell()
@property (weak, nonatomic) IBOutlet UIImageView *icoIamgeView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
//@property (weak, nonatomic) IBOutlet UILabel *sizeGameLabel;
@property (weak, nonatomic) IBOutlet UILabel *cishiLabel;
@property(strong, nonatomic) UILabel *onSaleLabel;

//@property (weak, nonatomic) IBOutlet UILabel *libaoLabel;
//@property (weak, nonatomic) IBOutlet UILabel *ViiVersiLabel;
//@property (weak, nonatomic) IBOutlet UILabel *topupLabel;
//@property (weak, nonatomic) IBOutlet UIButton *dowunlodeBut;

@property(strong,nonatomic) NSMutableArray *cunchuArr;

@end

@implementation HWOnlinegameTableCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.libaoLabel.layer.cornerRadius = 3;
    self.libaoLabel.layer.masksToBounds = YES;
    self.ViiVersiLabel.layer.cornerRadius = 3;
    self.ViiVersiLabel.layer.masksToBounds = YES;
    self.topupLabel.layer.cornerRadius = 3;
    self.topupLabel.layer.masksToBounds = YES;
    self.dowunlodeBut.layer.cornerRadius = 12;
    self.dowunlodeBut.layer.masksToBounds = YES;
    self.icoIamgeView.layer.cornerRadius = 8;
    self.icoIamgeView.layer.masksToBounds = YES;
    
    self.dowunlodeBut.userInteractionEnabled = NO;
    
      self.miaoshuLabel = [[UILabel alloc]initWithFrame:CGRectMake(79, 31, 200, 11)];
      self.miaoshuLabel.text = @"下载次数";
      self.miaoshuLabel.textColor = RGB(130, 130, 130);
      self.miaoshuLabel.font = [UIFont systemFontOfSize:11];
      self.miaoshuLabel.hidden = YES;
      [self.contentView addSubview:self.miaoshuLabel];
    
    
      self.jianjieLabe = [[UILabel alloc]initWithFrame:CGRectMake(79, 48, 200, 11)];
      self.jianjieLabe.text = @"nishi";
      self.jianjieLabe.textColor = RGB(130, 130, 130);
      self.jianjieLabe.font = [UIFont systemFontOfSize:12];
      self.jianjieLabe.hidden = NO;
      [self.contentView addSubview:self.jianjieLabe];
     
    
      self.nameLabel.textColor = RGB(51, 51, 51);
    
    
    self.dowunlodeBut.backgroundColor = QCchunseshensetupian;
    

    
    [self setUpUIView];
    
}

// 设置UI
- (void)setUpUIView {
    
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(79, 29, 13, 13)];
    imageView.image = [UIImage imageNamed:@"stars_ico"];
    self.penfenImageView = imageView;
    self.penfenImageView.hidden = YES;
    [self.contentView addSubview:imageView];
    UILabel *scorelabel = [[UILabel alloc]initWithFrame:CGRectMake(79+13+3, 29, 30, 13)];
    scorelabel.text = @"3.5";
    scorelabel.textColor = RGB(32, 132, 255);
    scorelabel.font = [UIFont systemFontOfSize:10];
    self.penfenLabel =scorelabel;
    self.penfenLabel.hidden = YES;
    [self.contentView addSubview:scorelabel];
    
    self.onSaleLabel = [[UILabel alloc] init];
    self.onSaleLabel.font = [UIFont systemFontOfSize:10];
    self.onSaleLabel.textColor = UIColor.whiteColor;
    self.onSaleLabel.backgroundColor = UIColor.redColor;
    self.onSaleLabel.layer.cornerRadius = 3;
    self.onSaleLabel.layer.masksToBounds = YES;
    [self.contentView addSubview:self.onSaleLabel];
    
    self.onSaleLabel.hidden = YES;
    [self.onSaleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.nameLabel.mas_right).offset(10);
        make.height.mas_equalTo(13);
        make.centerY.mas_equalTo(self.nameLabel);
        make.right.mas_lessThanOrEqualTo(-10);
    }];

}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setModel:(HWGameListModel *)model {
    _model = model;
     NSURL *url = [NSURL URLWithString:model.icon];
    [self.icoIamgeView sd_setImageWithURL:url placeholderImage:nil];
    
    self.nameLabel.text = model.name;
    
    
    self.sizeGameLabel.text = [NSString stringWithFormat:@"%@",model.size];
    
    
  //   self.cishiLabel.text = [NSString stringWithFormat:@"| %@  %@次下载",model.type,model.number];
     self.cishiLabel.text = [NSString stringWithFormat:@"| %@ ",model.type];
   //  self.cishiLabel.text  = @"";
    // self.cishiLabel.hidden = YES;
    
    if (model.zhekou.length > 0) {
        self.onSaleLabel.hidden = NO;
        if ([model.zhekou containsString:@"折"]) {
            self.onSaleLabel.text = [NSString stringWithFormat:@" %@ ",model.zhekou];
        } else {
            self.onSaleLabel.text = [NSString stringWithFormat:@" %@折 ",model.zhekou];
        }
        
        if ([self.onSaleLabel.text isEqualToString:@" 10折 "]) {
            self.onSaleLabel.hidden = YES;
        }
    } else {
        self.onSaleLabel.hidden = YES;
    }
    

  //  self.cishiLabel.backgroundColor = [UIColor redColor];
    self.libaoLabel.hidden = YES;
    self.ViiVersiLabel.hidden = YES;
    self.topupLabel.hidden = YES;
    self.jianjieLabe.hidden = YES;
    if (model.biaoqian.count > 0) {
        
        
        for (int i = 0; i < model.biaoqian.count; i++) {
            if (i == 0) {
              self.libaoLabel.hidden = NO;
              self.libaoLabel.text = [NSString stringWithFormat:@"%@",model.biaoqian[0]];
                
                
            } else if (i == 1){
                
                self.ViiVersiLabel.hidden = NO;
                self.ViiVersiLabel.text = [NSString stringWithFormat:@"%@",model.biaoqian[1]];
                
            } else {
                  self.topupLabel.hidden = NO;
                  self.topupLabel.text = [NSString stringWithFormat:@"%@",model.biaoqian[2]];
                
            }
        }

        
    } else {
        
//        self.libaoLabel.hidden = YES;
//        self.ViiVersiLabel.hidden = YES;
//        self.topupLabel.hidden = YES;
         self.jianjieLabe.hidden = NO;
        
         self.jianjieLabe.text = [NSString stringWithFormat:@"%@",model.summary];
        
        
        
    }
    
    
    if ([model.system_type isEqualToString:@"1"]) {
        
        self.sizeGameLabel.hidden = NO;
        self.cishiLabel.hidden = NO;
        self.miaoshuLabel.hidden = YES;
        
        
        NSString *chakan = [HWjianzhiduiObject keylocalization:@"查看"];
        [self.dowunlodeBut setTitle:chakan forState:UIControlStateNormal];
        
        //  [self.dowunlodeBut setTitle:@"查看" forState:UIControlStateNormal];
        
        
         
    } else if ( [model.system_type isEqualToString:@"2"]) {
        
        self.sizeGameLabel.hidden = YES;
        self.cishiLabel.hidden = YES;
         self.miaoshuLabel.hidden = NO;
         self.miaoshuLabel.text =[NSString stringWithFormat:@"下载次数%@",model.number];
         self.miaoshuLabel.text =[NSString stringWithFormat:@"玩过了有：%@人",model.number];
        
        
        
        NSString *dakai  = [HWjianzhiduiObject keylocalization:@"打开"];
         //  [self.dowunlodeBut setTitle:@"打开" forState:UIControlStateNormal];
        [self.dowunlodeBut setTitle:dakai forState:UIControlStateNormal];
        
        
    }
    
    //这个用来判断新游戏预告
    if(self.xuanzhongtap == 2) {
        
        
        self.sizeGameLabel.hidden = NO;
        self.cishiLabel.hidden = YES;
        self.miaoshuLabel.hidden = YES;
        
        self.libaoLabel.hidden = YES;
        self.ViiVersiLabel.hidden = YES;
        self.topupLabel.hidden = YES;
        self.jianjieLabe.hidden = NO;
        
        self.sizeGameLabel.text = [NSString stringWithFormat:@"%@",model.type];
        
        
           if ([model.system_type isEqualToString:@"1"]) {
                self.jianjieLabe.text = [NSString stringWithFormat:@"网络游戏   %@",model.shoufa];
           } else {
               
              self.jianjieLabe.text = [NSString stringWithFormat:@"H5游戏   %@",model.shoufa];
               
           }
        
        
        if ([model.shangjia isEqualToString:@"已上线"]) {
            
            [self.dowunlodeBut  setTitle:model.shangjia forState:UIControlStateNormal];
            self.dowunlodeBut.backgroundColor = RGB(174, 174, 174);
            
            
        } else {
            
             [self.dowunlodeBut  setTitle:model.shangjia forState:UIControlStateNormal];
             self.dowunlodeBut.backgroundColor = RGB(38, 154, 255);
            
        }
      
        
        
        
        
    }
    
    
    
      if (self.cunchuArr.count > 0 ) {
            
          //   self.cishiLabel
             [self.cishiLabel.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
             [self.miaoshuLabel.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
            
        }
        

        self.cunchuArr = [[NSMutableArray alloc]init];
    
        return;
        for (int i = 0 ; i < 5; i++) {


    //        UIImageView *iamgeViewxie1 = [[UIImageView alloc]initWithFrame:CGRectMake(30 + 8*i+2*i, 2,  8 , 8)];
    //          iamgeViewxie1.image = [UIImage imageNamed:@"stars_ico"];
    //          [self.cishiLabel   addSubview:iamgeViewxie1];
    //
    //
            if (self.miaoshuLabel.hidden == YES) {
                
                UIImageView *iamgeViewxie1 = [[UIImageView alloc]initWithFrame:CGRectMake(30 + 8*i+2*i, 2,  8 , 8)];
                        iamgeViewxie1.image = [UIImage imageNamed:@"stars_ico"];
                        [self.cishiLabel   addSubview:iamgeViewxie1];
                      
                 [self.cunchuArr addObject:iamgeViewxie1];
            } else {
                
                self.miaoshuLabel.text = @"";
                
                
                UIImageView *iamgeViewxie1 = [[UIImageView alloc]initWithFrame:CGRectMake(2+ 8*i+2*i, 1,  8 , 8)];
                                   iamgeViewxie1.image = [UIImage imageNamed:@"stars_ico"];
                                   [self.miaoshuLabel   addSubview:iamgeViewxie1];
                                 
                [self.cunchuArr addObject:iamgeViewxie1];
                
                
                
                
            }
            
            
       
          // [self.cunchuArr addObject:iamgeViewxie1];




        }
        
        
        
        
        NSLog(@"%@",model.point);
        
        if ([model.point intValue] == 5) {
            
            
                                 
        } else if ([model.point intValue] == 4) {
                                 UIImageView  *label1 =   self.cunchuArr[4];
                                 label1.image = [UIImage imageNamed:@"pingfen_weixuanzhong"];
                                 
                                //  label1.hidden = YES;
                                 
          }else if ([model.point intValue] == 3) {
                                 
                                 
                                 UIImageView  *label1 =   self.cunchuArr[4];
                                 //  label1.hidden = YES;
                                                
                                 UIImageView *label2 =   self.cunchuArr[3];
                                              //  label2.hidden = YES;
                                 
                                  label1.image = [UIImage imageNamed:@"pingfen_weixuanzhong"];
                                   label2.image = [UIImage imageNamed:@"pingfen_weixuanzhong"];
          }else if ([model.point intValue] == 2) {
                                 
                                 
                                 
                                            UIImageView *label1 =   self.cunchuArr[4];
                                            //   label1.hidden = YES;
                                                           
                                            UIImageView *label2 =   self.cunchuArr[3];
                                                //            label2.hidden = YES;
                                 
                                 
                                       UIImageView *label3 =   self.cunchuArr[2];
                                 
                                 
                                   label1.image = [UIImage imageNamed:@"pingfen_weixuanzhong"];
                                   label2.image = [UIImage imageNamed:@"pingfen_weixuanzhong"];
                                   label3.image = [UIImage imageNamed:@"pingfen_weixuanzhong"];
                                 
                                 
                                 
                                 
                                      //   label3.hidden = YES;
                                 
          }else if ([model.point intValue] == 1) {
                                 
                                 
                                       UIImageView *label1 =   self.cunchuArr[4];
                                       UIImageView *label2 =   self.cunchuArr[3];
                                       UIImageView *label3 =   self.cunchuArr[2];
                                       UIImageView *label4 =   self.cunchuArr[1];
                                 
                                 
                                  label1.image = [UIImage imageNamed:@"pingfen_weixuanzhong"];
                                   label2.image = [UIImage imageNamed:@"pingfen_weixuanzhong"];
                                   label3.image = [UIImage imageNamed:@"pingfen_weixuanzhong"];
                                  label4.image = [UIImage imageNamed:@"pingfen_weixuanzhong"];
                                 
                                 
                                  
                                           
                                 
           } else {
                                 
                                 
                                 UIImageView *label1 =   self.cunchuArr[4];
                                                  
                                                                                  
                                 UIImageView *label2 =   self.cunchuArr[3];
                                                                              
                                                        
                                                        
                                 UIImageView *label3 =   self.cunchuArr[2];
                                                           
                                              
                                 UIImageView *label4 =   self.cunchuArr[1];
                                               //  label4.hidden = YES;
                                 UIImageView *label5 =   self.cunchuArr[0];
                                                          //      label5.hidden = YES;
                                 
                                 
                                 label1.image = [UIImage imageNamed:@"pingfen_weixuanzhong"];
                                  label2.image = [UIImage imageNamed:@"pingfen_weixuanzhong"];
                                   label3.image = [UIImage imageNamed:@"pingfen_weixuanzhong"];
                                   label4.image = [UIImage imageNamed:@"pingfen_weixuanzhong"];
                                                 
                                   label5.image = [UIImage imageNamed:@"pingfen_weixuanzhong"];
                                                        
          }
                             
                   
        
        
    
    
    
    

}


-(void)setFenleimodel:(HWGameListModel *)fenleimodel {
    
    _fenleimodel = fenleimodel;
    
    NSURL *url = [NSURL URLWithString:fenleimodel.icon];
    [self.icoIamgeView sd_setImageWithURL:url placeholderImage:nil];
    
    self.nameLabel.text = fenleimodel.name;
    
    self.cishiLabel.text = [NSString stringWithFormat:@"%@次下载",fenleimodel.number];
    self.penfenLabel.text = [NSString stringWithFormat:@"%@",fenleimodel.point];
    
    self.libaoLabel.hidden = YES;
    self.ViiVersiLabel.hidden = YES;
    self.topupLabel.hidden = YES;
     self.jianjieLabe.hidden = YES;
    if (fenleimodel.biaoqian.count > 0) {
        
        
        for (int i = 0; i < fenleimodel.biaoqian.count; i++) {
            if (i == 0) {
                self.libaoLabel.hidden = NO;
                self.libaoLabel.text = [NSString stringWithFormat:@"%@",fenleimodel.biaoqian[0]];
                
                
            } else if (i == 1){
                
                self.ViiVersiLabel.hidden = NO;
                self.ViiVersiLabel.text = [NSString stringWithFormat:@"%@",fenleimodel.biaoqian[1]];
                
            } else {
                self.topupLabel.hidden = NO;
                self.topupLabel.text = [NSString stringWithFormat:@"%@",fenleimodel.biaoqian[2]];
                
            }
        }
        
        
    } else {
        
        //        self.libaoLabel.hidden = YES;
        //        self.ViiVersiLabel.hidden = YES;
        //        self.topupLabel.hidden = YES;
        self.jianjieLabe.hidden = NO;
        self.jianjieLabe.text = [NSString stringWithFormat:@"%@",fenleimodel.summary];
        
    }
    
    
    if ([fenleimodel.system_type isEqualToString:@"1"]) {
           
              [self.dowunlodeBut setTitle:@"查看" forState:UIControlStateNormal];
               
           
       } else {
             
           NSString *dakai  =    [HWjianzhiduiObject keylocalization:@"打开"];
           
            [self.dowunlodeBut setTitle:dakai forState:UIControlStateNormal];
             
      }
     
    
    
    
}

@end
